var express = require('express');
var router = express.Router();
// 该路由使用的中间件
router.use(function timeLog(req, res, next) {
  console.log('Time: ', Date.now());
  next();
});

//通过路由中间件做权限处理 router.use  router.post router.get
router.post(['/comment',"/queryArticles",'/deleteArticles'],function requireSignin(req, res, next) {
  //console.log(req)
    var user = req.session.sign;
    console.log('post路由中间件')
    if(!user){
        res.send({
            state:0,
            msg:'用户未登录'
        })
        return
    }
    if(user.role <-1){
        res.send({
            state:0,
            role:user.role,
            msg:'用户权限不足'
        })
        return
    }
  next();
});

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

module.exports = router;
